<?php
/* @var $this SmsmarketController */
/* @var $model Smsmarket */

$this->breadcrumbs=array(
	'Smsmarkets'=>array('index'),
	'Manage',
); 
?>
<script type="text/javascript">

  $(document).ready(function() {
     $('#savenew').click(function(){ 
        if($(this).val()=='编辑'){ 
            $('#newusers').removeAttr('disabled'); 
             $('#newusers').addClass('backgroundcolor'); 
            $('#newusers').focus();
            $(this).val('保存');
        }else{
             $('#newusers').attr('disabled','disabled'); 
               $('#newusers').removeClass('backgroundcolor'); 
            $(this).val('编辑');  
            selectsave();
        } 
      });

      $('#saveold').click(function(){
          if($(this).val()=='编辑'){ 
            $('#oldusers').removeAttr('disabled'); 
            $('#oldusers').addClass('backgroundcolor'); 
            $('#oldusers').focus();
            $(this).val('保存');
        }else{
            $('#oldusers').attr('disabled','disabled'); 
            $('#oldusers').removeClass('backgroundcolor'); 
            $(this).val('编辑');  
             selectsave();
        } 
      });

      
      check_count('newusers');
      check_count('oldusers');
      smspoint();
    });
  function check_count(string){ 
    var a=$("#"+string).val().length;  
     var ma=40-a; 
      if(string=='newusers'){ ma=ma-20; } 
     if(ma >=0){
        var st=ma;
        $("#input_ma_"+string).html('还能输入');
        $("#input_font_"+string).html('字');
     }else if(ma < 0){ 
        var st=-ma;
        $("#input_ma_"+string).html('已经超过');
        $("#input_font_"+string).html('字(将以多条发送)');
     }
    if(string=='newusers'){
      $('#newusersshow').val($("#"+string).val()+" 验证码:3345，【<?php echo $company->title;?>】");
    }
    $("#"+string+"len").html(st);     
  }
    function smspoint(){
       if($('#oldsendstatus').val()==1){
                $('#oldpoint').html('重要警告:开启向老会员发送短信,老会员连接就会产生短信费用!');
              }else{
                $('#oldpoint').html('');
              }
    }
    function selectsave(){ 
        smspoint();
        $.post("<?php echo Yii::app()->createUrl('smsmarket/ajaxsave')?>",
            {'oldsendstatus':$('#oldsendstatus').val(),'newusers':$('#newusers').val(),'oldusers':$('#oldusers').val(),'id':<?php echo $model->id;?>},
            function(result){ 
            if(result.code ==0){
            }
        },'json');
    }  
</script>

<h1>短信营销</h1>

<div class="form allrow"> 
    <div class="row bordiv">
        <div class="row ">         
            <span class=" " >一共能输入20个字,</span>              
            <span class=" " id="input_ma_newusers">还能输入</span>
            <span class="candara"><span id="newuserslen"></span></span>
            <span class=" mr2p " id="input_font_newusers">字</span>  
        </div> 
        <div class="row">
            <?php echo CHtml::label("向新会员发送(获取验证码)",false,array('style'=>'width:30%;'));  ?>
            <?php echo CHtml::textArea('newusers',(empty($model->newusers)?'':$model->newusers),array('id'=>'newusers','disabled='=>'disabled',"onkeyup"=>"check_count('newusers')"));  ?> 
        </div> 
        <div class="row">
            <?php echo CHtml::label("短信释义",false,array('style'=>'width:30%;'));  ?>
            <?php echo CHtml::textArea('newusersshow','',array('id'=>'newusersshow','disabled='=>'disabled'));  ?> 
        </div> 
        <div class="row buttons">
                <?php echo CHtml::submitButton('编辑',array('class'=>'subButton','id'=>'savenew')); ?>
        </div>
    </div>
    <div class="row bordiv">
       <div class="row">  
            <span class="candara" id="oldpoint"></span>    
        </div> 
       <div class="row">  
        <?php echo CHtml::label("向老会员发送短信状态",false,array('style'=>'width:30%;'));  ?>
        <?php echo CHtml::dropDownList( 
                  'oldsendstatus',
                  $model->oldsendstatus,
                CHtml::listData(
                    array(array('id'=>0,'title'=>'关闭'),array('id'=>1,'title'=>'开启')),
                    'id',
                    'title'
                ),array('id'=>'oldsendstatus','AutoPostBack'=>true,'onchange'=>'selectsave();')
            );  ?> 
        </div>  
         <div class="row">  
            <span class=" " >一共能输入40个字,</span>                       
            <span class=" " id="input_ma_oldusers">还能输入</span>
            <span class="candara"><span id="olduserslen"></span></span>
            <span class=" mr2p " id="input_font_oldusers">字</span> 
        </div> 
        <div class="row">
            <?php echo CHtml::label("向老会员发送(登陆后)",false ,array('style'=>'width:30%;'));  ?>
            <?php echo CHtml::textArea('oldusers',(empty($model->oldusers)?'':$model->oldusers),array('id'=>'oldusers','disabled='=>'disabled',"onkeyup"=>"check_count('oldusers')"));  ?> 
        </div> 
        <div class="row buttons">
                <?php echo CHtml::submitButton('编辑',array('class'=>'subButton','id'=>'saveold')); ?>
        </div>
    </div>
</div>
